﻿
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class reloader
    Inherits cacheProcessor

    Public Const _pathidentity As String = "/reloader"

    Public Class query
        Public Const url As String = "url"
        Public Const timeout As String = "timeout"
    End Class

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Protected Overrides Function processImpl(ByVal context As httpContext) As Boolean
        Dim page As xhtmlpage = Nothing
        page = New xhtmlpage(context.buff())
        page.title().text = applicationSign() + " - reloader"
        Dim url As String
        Dim timeout As String
        url = context.url.query(query.url)
        timeout = context.url.query(query.timeout)
        If isemptystring(url) Then
            page.title().text += " - input url"
            iframeJumpKeeper.invoke(page)

            Dim form As form = Nothing
            form = New form(context.buff())
            form.action = strmid(_pathidentity, strlen(network.pathSeperator))
            page.body().addchild(form)

            Dim label As label = Nothing
            label = New label(context.buff())
            label.text = "please input link here."
            form.addchild(label)

            form.addchild(New br(context.buff()))

            Dim input As input = Nothing
            input = New input(context.buff())
            input.type = xhtmlctrl.input.type_enum.text
            input.name = query.url
            form.addchild(input)

            form.addchild(New br(context.buff()))

            label = New label(context.buff())
            label.text = "please input timeout (second) here."
            form.addchild(label)

            form.addchild(New br(context.buff()))

            input = New input(context.buff())
            input.type = xhtmlctrl.input.type_enum.text
            input.name = query.timeout
            input.value = timeout
            form.addchild(input)

            form.addchild(New br(context.buff()))

            input = New input(context.buff())
            input.type = xhtmlctrl.input.type_enum.submit
            input.value = "submit"
            form.addchild(input)
        Else
            page.title().text += " - " + url

            Dim reloader As delayReloader = Nothing
            Dim temp As Int32
            reloader = New delayReloader(context.buff())
            reloader.delay = ifoper(isemptystring(timeout) OrElse Not convertor.toint32(timeout, temp), "20", timeout)
            page.head().addchild(reloader)

            Dim iframe As iframe = Nothing
            iframe = New iframe(context.buff())
            iframe.frameborder = 0
            iframe.marginheight = 0
            iframe.marginwidth = 0
            url = urlUtils.htmldecode(url)
            iframe.src = ifoper(Not availableAddress(url), network.httpAddressHeader + url, url)
            iframe.width = "100%"
            iframe.height = 768
            page.body().addchild(iframe)
        End If

        Return page.render()
    End Function
End Class
